﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace WFL.Office.Word
{
    public class WordTable
    {
        private readonly object _lock = new object();

        private WordBorders _borders;
        public WordBorders Borders
        {
            get
            {
                if (_borders == null)
                {
                    lock (_lock) { if (_borders == null) { _borders = new WordBorders(_table.Borders); } }
                }
                return _borders;
            }
        }

        private TableColumns _columns;
        public TableColumns Columns
        {
            get
            {
                if (_columns == null)
                {
                    lock (_lock) { if (_columns == null) { _columns = new TableColumns(_table.Columns) { Table = this }; } }
                }
                return _columns;
            }
        }

        private TableRows _rows;
        public TableRows Rows
        {
            get
            {
                if (_rows == null)
                {
                    lock (_lock) { if (_rows == null) { _rows = new TableRows(_table.Rows) { Table = this }; } }
                }
                return _rows;
            }
        }


        #region 单元格边距、间距

        public float TopPadding
        {
            get { return _table.TopPadding; }
            set { _table.TopPadding = value; }
        }

        public float BottomPadding
        {
            get { return _table.BottomPadding; }
            set { _table.BottomPadding = value; }
        }

        public float LeftPadding
        {
            get { return _table.LeftPadding; }
            set { _table.LeftPadding = value; }
        }

        public float RightPadding
        {
            get { return _table.RightPadding; }
            set { _table.RightPadding = value; }
        }

        /// <summary>
        /// 单元格间距
        /// </summary>
        public float Spacing
        {
            get { return _table.Spacing; }
            set { _table.Spacing = value; }
        }

        #endregion


        private Table _table;

        public WordDocument Document
        {
            get;
            internal set;
        }

        internal WordTable(Table table)
        {
            _table = table;
        }

        public TableCell Cell(int row, int column)
        {
            return new TableCell(_table.Cell(row, column)) { Table = this };
        }


    }
}
